//
//  HMApplyTimeCollection.m
//  仿真开发
//
//  Created by LZH on 2017/3/26.
//  Copyright © 2017年 B.HOPE. All rights reserved.
//

#import "HMApplyTimeCollection.h"
#import <Masonry.h>

@interface HMApplyTimeCollection ()
@property(strong,nonatomic)NSMutableArray<UILabel *> *labelArr;

@end

@implementation HMApplyTimeCollection

static NSString * const reuseIdentifier = @"Cell";

-(instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout{
    
    if (self=[super initWithCollectionViewLayout:layout]) {
        [self setupUI];
    }
    return self ;
}

-(void)setupUI{
    
    _labelArr=[NSMutableArray arrayWithCapacity:32];
    
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
   // self.collectionView.backgroundColor = [UIColor blackColor];
}



#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 32;
}


//设置每个cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
   cell.contentView.backgroundColor=[UIColor whiteColor];
    
    
    UILabel *label = [UILabel new];
 
    
    label.font = [UIFont systemFontOfSize:12];
    label.textColor = [UIColor blackColor];
    
    label.textAlignment = NSTextAlignmentCenter;
    [cell.contentView addSubview:label];
    
    //设置约束
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cell.contentView);
        make.left.right.equalTo(cell.contentView);
        
    }];
    
    switch (indexPath.item) {
        case 0:
            label.text = @"时间";
            break;
        case 1:
            label.text = @"星期一";
            break;
        case 2:
            label.text = @"星期二";
            break;
        case 3:
            label.text = @"星期三";
            break;
        case 4:
            label.text = @"星期四";
            break;
        case 5:
            label.text = @"星期五";
            break;
        case 6:
            label.text = @"星期六";
            break;
        case 7:
            label.text = @"星期日";
            break;
        case 8:
            label.text = @"上午";
            break;
        case 9:
            label.text = @"有号";
            break;
        case 16:
            label.text = @"下午";
            break;
        case 20:
            label.text = @"有号";
            break;
        case 24:
            label.text = @"晚上";
            break;
        case 29:
            label.text = @"有号";
            break;
        default:
            break;
    }

    //记录每个label
      [self.labelArr addObject:label];
     return cell;
}



//监听点击方法

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.item == 9 || indexPath.item == 20 || indexPath.item == 29) {
        if ([self.labelArr[indexPath.item].text isEqualToString:@"已约"]) {
            self.labelArr[indexPath.item].text = @"有号";
            
        }
        else if([self.labelArr[indexPath.item].text isEqualToString:@"有号"]){
            self.labelArr[indexPath.item].text = @"已约";
            
        }
    }
}
@end
